package com.elock.service.serviceImpl;

import java.util.Date;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.elock.base.core.Page;
import com.elock.base.core.Pageable;
import com.elock.base.core.service.impl.BaseServiceImpl;
import com.elock.base.core.util.DateUtil;
import com.elock.dao.WarningMessageProcessDao;
import com.elock.entity.WarningMessageProcess;
import com.elock.service.MemberService;
import com.elock.service.WarningMessageProcessService;

/**
 * 终端设备用户关联
 * @author 仁德
 */
@Service("warningMessageProcessServiceImpl")
public class WarningMessageProcessServiceImpl extends
		BaseServiceImpl<WarningMessageProcess> implements WarningMessageProcessService {

	@Resource(name = "warningMessageProcessDao")
	private WarningMessageProcessDao warningMessageProcessDao;
	@Resource(name = "memberServiceImpl")
	private MemberService memberService;

	@Override
	@Transactional(readOnly = true)
	public Page<Map<String, Object>> findPage(String terminalNum, String elockNum,
			String carNum, Integer flag, String version, Pageable pageable) {
		return warningMessageProcessDao.findPage(terminalNum,
				elockNum,
				carNum,
				flag,
				version,
				pageable);
	}

	@Override
	@Transactional
	public void handle(Long[] ids) {

		String idss = "";
		for (Long iid : ids) {
			idss += "," + iid;
		}
		idss = idss.substring(1);

		String sql = "update warning_message_process set is_process=1,processor=?,process_time=? where id in ("
				+ idss
				+ ") and is_process=0";
		warningMessageProcessDao.getNativeDao().update(sql,
				new Object[] { memberService.getCurrent().getUsername(),
						DateUtil.convert(new Date()) });
	}
}
